/*
 * @Author: gitee_com_zb
 * @Date: 2024-12-09 09:49:33
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-12-09 09:49:49
 * @FilePath: /algorithm/每日一题9.有效的括号(easy).cpp
 * @Description: 题目链接 https://leetcode.cn/problems/valid-parentheses
 */
class Solution {
public:
    bool isValid(string s) 
    {
        std::stack<char> st;
        std::map<char,char> matchMap;
        matchMap['[']=']';
        matchMap['{']='}';
        matchMap['(']=')';
        for(auto &ch:s)
        {
            if(matchMap.count(ch)) st.push(ch);
            else {
                if(st.empty()) return false;
                char topVal=st.top();
                st.pop();
                if(matchMap[topVal]!=ch) return false;
            }
        }
        return st.empty();
    }
};